import axios from 'axios'
import qs from 'qs'

// 默认请求地址
axios.defaults.baseURL = 'http://192.168.0.103:9000'

// 响应时间
axios.defaults.timeout = 120000
// 配置请求头
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'
// 传参序列化
axios.interceptors.request.use(function (config) {
    if (config.form) {
        config.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
        if (config.method === 'post') {
            config.data = qs.stringify(config.data)
        }
    } else {
        config.headers['Content-Type'] = 'application/json;charset=UTF-8'
    }
    return config
}, function (error) {
    // Do something with request error
    return Promise.reject(error)
})
